import request from '@/utils/http'
import {
	AuthVerify,
	Enable2fa,
	Login,
	LoginVerify,
	ThirdPartyInfo,
	ThirdPartyRegister
} from '@/api/account-type.ts'

const PATH = '/auth/accounts'

export function register(data: any) {
	return request({ url: PATH + '/register', method: 'post', data })
}

export function login(data: Login['params']) {
	return request<Login['result']>({ url: PATH + '/login', method: 'post', data })
}

export function loginVerifyCode(data: LoginVerify['params']) {
	return request<LoginVerify['result']>({ url: PATH + '/verifyCode', method: 'post', data })
}

export function mobilePasswordResetVerify(data: any) {
	return request({ url: `${PATH}/mobilePasswordResetVerify`, method: 'post', data })
}

export function authVerifyCode(data: AuthVerify['params']) {
	return request<AuthVerify['result']>({ url: 'user/auth/verifyCode', method: 'post', data })
}

export function logout() {
	return request({ url: PATH + '/logout', method: 'post' })
}

export function resetPasswordRequest(data: any) {
	return request({ url: PATH + '/requestPasswordReset', method: 'post', data })
}

export function resetPassword(data: any) {
	return request({ url: PATH + '/passwordReset', method: 'post', data })
}

export function checkUsername(username: string) {
	return request({ url: `/user/auth/check/${username}`, method: 'get' })
}

export function generateGoogleSecretKey() {
	return request({ url: `/user/profile/generateGoogleSecretKey`, method: 'get' })
}

export function updatePassword(data: any) {
	return request({ url: `/user/profile/updatePassword`, method: 'post', data })
}

export function updateEmail(data: any) {
	return request({ url: `/user/profile/updateEmail`, method: 'post', data })
}

export function updateMobile(data: any) {
	return request({ url: `/user/profile/updateMobile`, method: 'post', data })
}

export function enable2fa(data: Enable2fa['params']) {
	return request<Enable2fa['result']>({ url: `/user/profile/enable2fa`, method: 'post', data })
}

export function disable2fa(data: any) {
	return request({ url: `/user/profile/disable2fa`, method: 'post', data })
}

export function updateIncognitoMode(data: any) {
	return request({ url: `/user/profile/updateIncognitoMode`, method: 'post', data })
}

export function updatePrivateMode(data: any) {
	return request({ url: `/user/profile/updatePrivateMode`, method: 'post', data })
}

export function updateEnablePush(data: any) {
	return request({ url: `/user/profile/updateEnablePush`, method: 'post', data })
}

export function checkAccount(data: any) {
	return request({ url: PATH + '/checkaccount', method: 'post', data })
}

export function getLocation() {
	return request({ url: PATH + '/getlocation', method: 'get' })
}

export function setLocation(data: any) {
	return request({ url: PATH + '/setlocation', method: 'post', data })
}

export function checkToken() {
	return request({ url: PATH + '/checktoken', method: 'get' })
}

// 第三方登录请求
export function thirdPartyRequest(params: any) {
	return request({ url: PATH + `/authBinding/${params.source}`, method: 'get', params })
}

// 第三方账号信息
export function thirdPartyInfo(data: ThirdPartyInfo['params']) {
	return request<ThirdPartyInfo['result']>({ url: PATH + `/thirdPartyInfo`, method: 'post', data })
}

// 第三方登录/注册
export function thirdPartyRegister(data: ThirdPartyRegister['params']) {
	return request<ThirdPartyRegister['result']>({
		url: PATH + '/thirdPartyRegister',
		method: 'post',
		data
	})
}
